HeroViewFunc={}
HeroView={}
HeroViewFunc.__index=HeroViewFunc
setmetatable(HeroView, HeroViewFunc)

HeroViewFunc.release = function(self)
  print("HeroViewFunc.release", self)
  self.parent:removeChild(self.normalView, true)
  self.parent:removeChild(self.hpView, true)
  self.parent:removeChild(self.spView, true)
  self.parent:removeChild(self.bkHpView, true)
end

HeroViewFunc.create = function(parent, name, position)
  heroView={}
  setmetatable(heroView, HeroViewFunc)
 
  heroView.parent=parent 

  CCSpriteFrameCache:sharedSpriteFrameCache():addSpriteFramesWithFile(string.format("%s.plist", name))
  local sp = CCSprite:createWithSpriteFrameName(string.format("%s_std_1.png", name))
  sp:setPosition(position)
  sp:setFlipX(flip)
  parent:addChild(sp)

  local bksp = CCSprite:create("war_hp_bg.png")
  local hpsp = CCSprite:create("war_hp.png")
  local spsp = CCSprite:create("war_sp.png")
  local hpbar = CCProgressTimer:create(hpsp)
  local spbar = CCProgressTimer:create(spsp)
  hpbar:setType(kCCProgressTimerTypeBar)
  hpbar:setPercentage(100.0)
  hpbar:setMidpoint(ccp(0,0))
  hpbar:setBarChangeRate(ccp(1, 0))
  spbar:setType(kCCProgressTimerTypeBar)
  spbar:setPercentage(100.0)
  spbar:setMidpoint(ccp(0,0))
  spbar:setBarChangeRate(ccp(1, 0))

  parent:addChild(bksp)
  parent:addChild(hpbar)
  parent:addChild(spbar)
  bksp:setPosition(position.x,position.y+80)
  hpbar:setPosition(position.x,position.y+80+5)
  spbar:setPosition(position.x,position.y+80-5)
  
  hero.normalView = sp 
  hero.hpView = hpbar
  hero.spView = spbar
  hero.bkHpView = bksp 

  return hero
end
